package com.app.allwe.gui.countdown;

import javax.swing.*;

public class CountdownThread extends Thread{
    private int time;
    private JLabel timeLabel;

    public CountdownThread(int time, JLabel timeLabel) {
        this.time = time;
        this.timeLabel = timeLabel;
    }

    @Override
    public void run() {
        while (time > 0) {
            try {
                timeLabel.setText(String.valueOf(time));
                timeLabel.repaint();
                time--; // 倒计时减1
                Thread.sleep(1000); // 每次等待1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
